#!/usr/bin/python3
import sys
import re

# part 1

def is_visible(string, element):
    return int(element) == max([int(e) for e in string]) and string.count(element) == 1

def part1():
    grid = [line.strip() for line in sys.stdin]
    gridT = [''.join([grid[row][col] for row in range(len(grid))]) for col in range(len(grid[0]))]
    #print(grid, gridT)

    visible = len(grid[0]) + len(grid[-1]) + len(gridT[0]) + len(gridT[-1]) - 4
    for y in range(1, len(gridT) - 1):
        for x in range(1, len(grid) - 1):
            element = grid[y][x]
            can_be_seen = is_visible(grid[y][:x + 1], element) or \
                          is_visible(grid[y][x:], element) or \
                          is_visible(gridT[x][:y + 1], element) or \
                          is_visible(gridT[x][y:], element)
            visible += 1 if can_be_seen else 0
            #print(y, x, 'is visible' if can_be_seen else 'is not visible')
    print(f'{visible} visible trees')

# part 2

def count_smaller(string):
    for i, c in enumerate(string[1:]):
        if c >= string[0]:
            return i + 1
    return len(string) - 1

def part2():
    grid = [line.strip() for line in sys.stdin]
    gridT = [''.join([grid[row][col] for row in range(len(grid))]) for col in range(len(grid[0]))]

    max_score = 0
    for y in range(1, len(gridT) - 1):
        for x in range(1, len(grid) - 1):
            element = grid[y][x]
            scenic_left = count_smaller(grid[y][:x + 1][::-1])
            scenic_right = count_smaller(grid[y][x:])
            scenic_up = count_smaller(gridT[x][:y + 1][::-1])
            scenic_down = count_smaller(gridT[x][y:])
            #print(scenic_up, scenic_left, scenic_down, scenic_right)
            scenic_score = scenic_left * scenic_right * scenic_up * scenic_down
            if scenic_score > max_score:
                max_score = scenic_score
                print(f'new max scenic score of {max_score}')

if sys.argv[1] in '1':
    part1()
else:
    part2()